package com.card.admin;

import java.util.List;

import com.google.common.collect.Lists;
import com.xiaoao.net.db.Entity;
import com.xiaoao.net.db.Key;
import com.xiaoao.net.db.Query;
import com.xiaoao.net.db.mongo.MongodbManager;
import com.xiaoao.net.utils.PrimaryKey;
import com.xiaoao.net.utils.json.GSONUtils;

public class FeedBackManager {
	public static final String T_DATA_FEEDBACK="feedBack";
	
	private static FeedBackManager instance;
	public static FeedBackManager getInstance() {
		if(instance == null) {
			instance = new FeedBackManager();
		}
		return instance;
	}

	public void save(String phone,String content) {
		Entity entity = new Entity(new Key(T_DATA_FEEDBACK,String.valueOf(PrimaryKey.getIntPrimaryKey(T_DATA_FEEDBACK))));
		entity.setProperty("data", GSONUtils.ToJSONString(new FeedBack(phone, content)));
		MongodbManager.getInstance().saveOrUpdate(entity);
	}
	
	public List<FeedBack> getAll() {
		List<FeedBack> fbs = Lists.newArrayList();
		Query query = new Query( FeedBackManager.T_DATA_FEEDBACK);
		query.setLimit(100000);
		List<Entity> list = MongodbManager.getInstance().queryEntity(query);
		for (Entity entity : list) {
			String data = (String)entity.getProperty("data");
			FeedBack fb = GSONUtils.FromJSONString(data, FeedBack.class);
			fbs.add(fb);
		}
		return fbs;
	}
	
	public static void main(String[] args) {
		FeedBackManager.getInstance().save("12", "sdalhsfjka");
	}
}
